package com.company.springhibernate.dao;

import java.util.Collection;
import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.company.modelo.Student;

public class HibernateStudentDao implements StudentDao {

	HibernateTemplate hibernateTemplate;
	
	public HibernateTemplate getHibernateTemplate() {
		  return hibernateTemplate;
	}
		 
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
	       this.hibernateTemplate = hibernateTemplate;
	}
		 
	public Student getStudent(Integer id) {
		return (Student) getHibernateTemplate().get(Student.class, new Integer(id));
	}

	public List<Student> getAllStudents() {
		return getHibernateTemplate().find("from Student std order by std.lastName, std.firstName");
	}

	public List<Student> getGraduatedStudents() {
		return getHibernateTemplate().find("from Student std where std.status=1");
	}

	public List<Student> findStudents(String lastName) {
		return getHibernateTemplate().find("from Student std where std.lastName like ?", lastName + "%");
	}

	public void saveStudent(Student std) {
		getHibernateTemplate().saveOrUpdate(std);
	}

	public void removeStudent(Student std) {
		 getHibernateTemplate().delete(std);
	}

	
}
